####
#Set-HostFile
#Created by 
#Nate Bruneau / IS Engineering
####

Write-Host -ForegroundColor Yellow "Host-File: Adding Host file for $env:farmname."

$servers=Get-SPServer

foreach( $server in $servers )
{
	if( $server.Role -eq "WebFrontEnd" -OR $server.Role -eq "Application" )
	{
	$server = $server.Name
	
	$ServerOS = gwmi win32_operatingsystem -computer $server
	$sysDrive = $ServerOS.SystemDrive
	$sysDriveLetter = $sysDrive[0]
	
	$hostfilepath = "\\$server\$sysDriveLetter$\Windows\System32\drivers\etc\hosts";
	$hostfile = Get-Content $hostfilepath

		if ($hostfile -like "*$env:farmname*"){
		
		#Write-Host "Host-File has already been added to $server"
		} else {
		Write-Host "Adding Host file entry for $env:farmname to $server"
		Add-Content $hostfilepath "127.0.0.1		$env:farmname"
		}
	}
}

Write-Host -ForegroundColor Yellow "Host-File: Adding Host file for $env:farmname. : COMPLETED"

